package interview.movestars;

public class MoveStars {
	public int move(char[] str) {
		int ptrStar, ptrChar;
		int count = 0;
		ptrStar = str.length - 1;
		while(true) {
			while(ptrStar >= 0 && str[ptrStar] != '*') {
				ptrStar--;
			}
			if(ptrStar < 0) {
				break;
			}

			ptrChar = ptrStar;
			while(ptrChar >= 0 && str[ptrChar] == '*') {
				ptrChar--;
			}
			if(ptrChar < 0) {
				break;
			}
			char temp = str[ptrChar];
			str[ptrChar] = str[ptrStar];
			str[ptrStar] = temp;
			count++;
			ptrStar--;
		}
		return count;
	}
}
